/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.fvaz.demo.utils;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author felipe
 */
public class AppHandler extends DefaultHandler {

    private boolean bValidator;
    private String appName;
    
    public AppHandler( String appName) {
        
        super();
        this.appName = appName;
        
    }
    
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

        if (qName.equalsIgnoreCase("app") && appName.equalsIgnoreCase( attributes.getValue("name"))) {
            
            ConfigurationReader.app.setName( attributes.getValue("name"));
            
        }

        
        if (qName.equalsIgnoreCase("validator") && ConfigurationReader.app.getName() != null) {
            
            ConfigurationReader.app.setView( attributes.getValue("view"));
            bValidator = true;
            
        }

    }

    public void endElement(String uri, String localName, String qName) throws SAXException {}

    public void characters(char ch[], int start, int length) throws SAXException {

       if (bValidator) {
            
            ConfigurationReader.app.setClassName( new String(ch, start, length));
            bValidator = false;
            
        }

    }

    //début du parsing
    public void startDocument() throws SAXException {}
    
    //fin du parsing
    public void endDocument() throws SAXException {}
}
